package Flink.source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class FileSourceDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 从文件读取数据
        /*
        * 参数可以是目录，也可以是文件；还可以从HDFS目录下读取，使用路径hdfs://...
        *
        * */
        FileSource<String> fileSource = FileSource.forRecordStreamFormat(
                new TextLineInputFormat(),
                new Path("Flink/input/word.txt")
        ).build();
        env.fromSource(fileSource, WatermarkStrategy.noWatermarks(), "fileSource")
                .print();
        env.execute();
    }
}
